﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace BookStoreService.Core.Repository
{
    //Mock repository class that implements IRepository inteface on in-memory collection
    public abstract class MockRepository<T> : IRepository<T> where T : class
    {
        private readonly Dictionary<Type, List<T>> m_dictionary = new Dictionary<Type, List<T>>();

        public List<T> List
        {
            get
            {
                return m_dictionary[typeof(T)];
            }
        }

        #region IRepository<T> Members

        public IQueryable<T> Query()
        {
            return List.AsQueryable();
        }

        public void Add(T entity)
        {
            List.Add(entity);
        }

        public void Remove(T entity)
        {
            List.Remove(entity);
        }

        public void Attach(T current, T original)
        {            
        }

        public void Attach(T current)
        {         
        }

        public void SubmitChanges()
        {         
        }

        #endregion
    }
}
